"""
7-7 约瑟夫环
"""


def resolution1():
    a = int(input())
    numbers = []
    for numb in range(1, a+1):
        numbers.append(numb)
    length = len(numbers)
    count = 1
    index = 0
    while length > 1:
        if count == 3:
            count = 1
            numbers.remove(numbers[index % length])
            print(numbers)
            length = len(numbers)
            # print(length)
        count += 1
        index += 1
    print(numbers[0])


if __name__ == '__main__':
    resolution1()